package com.zenglx.assembly.increasingSequence.impl;

import com.zenglx.assembly.increasingSequence.api.SequenceGeneratorApi;
import com.zenglx.assembly.increasingSequence.api.SequenceGeneratorConstant;
import com.zenglx.assembly.increasingSequence.impl.dao.SequenceGeneratorDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;


/**
 * 存储过程 序列生成器
 * @author zengliangxi
 */
@ConditionalOnProperty(name = SequenceGeneratorConstant.SEQUENCE_GENERATOR_TYPE
        ,  havingValue = SequenceGeneratorConstant.SEQUENCE_GENERATOR_TYPE_PROCEDURE)
@Component
@Slf4j
public class ProcedureSequenceGenerator implements SequenceGeneratorApi {

    @Autowired
    private SequenceGeneratorDao sequenceGeneratorDao;
    /**
     * 下一个Id
     *
     * @return id
     */
    @Override
    public String nextId(String key) {
        //log.info("存储过程序列key:{}",key);
        long seqVal = sequenceGeneratorDao.getByProcedure(key);
        //log.info("存储过程序列val:{}",seqVal);
        return String.valueOf(seqVal);
    }
}
